<?php

namespace app\channel\controller\api;
use app\channel\ApiController;


/*------------------------------------------------------ */
//-- 公共查询API，不限制登陆
/*------------------------------------------------------ */

class Publics extends ApiController
{
    /*------------------------------------------------------ */
    //-- 优先执行
    /*------------------------------------------------------ */
    public function initialize()
    {
        parent::initialize(false);
    }
    /*------------------------------------------------------ */
    //-- 查询代理授权信息
    /*------------------------------------------------------ */
    public function getAuthorizedInfo(){
        $field = input('field','mobile','trim');
        $value = input('value','','trim');
        $ProxyUsersModel = new \app\channel\model\ProxyUsersModel();
        if ($field == 'my'){
            $userInfo = $this->userInfo;
        }else{
            $user_id = $ProxyUsersModel->getUserIdByField($field,$value);
            if (is_numeric($user_id) == false){
                return $this->error([$user_id,-1]);
            }
            $userInfo = $ProxyUsersModel->info($user_id);
        }

        if ($userInfo['status'] == 9){
            return $this->error(['相关代理已被冻结.',-1]);
        }
        if ($userInfo['status'] != 1){
            return $this->error(['相关代理暂未通过审核.',-1]);
        }
        if ($userInfo['warrant_end_time'] < time()){
            $data['warrant_end_time'] = '授权已过期';
        }else{
            $data['warrant_end_time'] = dateTpl($userInfo['warrant_end_time'],'Y-m-d H:i:s',true);
        }
        $data['real_name'] = $userInfo['byUser']['real_name'];
        $data['proxy_name'] = $userInfo['proxyLevel']['proxy_name'];
        $data['img_err'] = 0;
        $returnImg = $ProxyUsersModel->getAuthorizedImg($userInfo);
        if ($returnImg !== false){
            $data['img_url'] = $returnImg['file'];
            $data['share_url'] = $returnImg['url'];
        }
        return $this->success($data);
    }
}

